package com.fingard.dsp.bank.directbank.spdb01;

import com.alipay.api.domain.CodeNOList;
import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import com.gnete.bc.LICENSE;
import com.ibm.wsdl.util.xml.QNameUtils;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.*;

/**
 * Created by F on 2018/8/22.
 */
public class SPDB01ElecBillTrans extends SPDB01Base implements IElecBillTrans {
    private static final String INSERTRECEIPT = "INSERT INTO REQSEQIDMAPPING(URID,BANKCODE,BUSITYPE,TRANSDATE,REQSEQID,BANKREQSEQID) values (?,?,?,?,?,?);";
    private static final String SELECTRECEIPT = "SELECT TRANSDATE,REQSEQID,BANKREQSEQID,BUSITYPE FROM REQSEQIDMAPPING WHERE BANKREQSEQID=?;";
    private static final String INSERTCANCEL ="INSERT INTO CANCELOPERATIONS(URID,BANKCODE," +
            "BUSITYPE,OUTREQSEQID,TRANSDATE," +
            "BILLNO,BILLAMOUNT,BILLTYPE,ISSDATE,DUEDATE,TRANSFLAG," +
            "DRAWERNAME,DRAWERACTNO,DRAWERBANKCODE,DRAWERBANKNAME," +
            "ACCEPTORNAME,ACCEPTORACTNO,ACCEPTORBANKCODE,ACCEPTORBANKNAME," +
            "RECEIVERNAME,RECEIVERACTNO,RECEIVERBANKCODE,RECEIVERBANKNAME," +
            "ISFINISHED,ISCANCEL) values \n" +
            "(?,?,?,?,?," +
            "?,?,?,?,?,?," +
            "?,?,?,?," +
            "?,?,?,?," +
            "?,?,?,?,1,1);";
    private static final String UPDATECANCEL = "UPDATE CANCELOPERATIONS SET ISFINISHED =? WHERE OUTREQSEQID=? AND BILLNO =? and ISFINISHED=1 AND ISCANCEL=1;";
    //签收应答
    @Override
    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception {
        RetAtsB003BillRespSubmit retAts = new RetAtsB003BillRespSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()) {
            RetAtsB003BillRespSubmitDetail detail = new RetAtsB003BillRespSubmitDetail();
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE06";
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <eBillBusinessId></eBillBusinessId>
                xmlTextWriter.writeElementString("eBillBusinessId",String.format("%-20s",query.detail.busiNo));//业务ID(20)
//                <eBillBusinessType></eBillBusinessType>
                //    应答类型 1-承兑应答 2-收票应答 3-背书转让应答 4-回购式贴现赎回应答 5-质押解除应答 6-提示付款应答 7-保证应答 8-同意清偿应
                String eBillBusinessType="";
                switch (Integer.valueOf(query.detail.respType)){
                    case 1:
                        eBillBusinessType = "02";
                        break;
                    case 2:
                        eBillBusinessType = "03";
                        break;
                    case 3:
                        eBillBusinessType = "05";
                        break;
                    case 4:
                        eBillBusinessType = "07";
                        break;
                    case 5:
                        eBillBusinessType = "16";
                        break;
                    case 6:
                        if ("1".equals(query.detail.proPayType)) {
                            eBillBusinessType = "17";
                        } else {
                            eBillBusinessType = "18";
                        }
                        break;
                    case 7:new Exception("银行暂不支持改类型的应答签收");break;
                    case 8:eBillBusinessType = "20";break;
                    case 9:eBillBusinessType = "15";break;//质押签收
                    default:{
                        new Exception("应答类型异常："+query.detail.respType);
                    }
                }
                xmlTextWriter.writeElementString("eBillBusinessType",eBillBusinessType);//业务类型(2)
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));
//                <unconditionalPayConsign></unconditionalPayConsign>
                if("1".equals(query.detail.respType)) {
                    if("1".equals(query.detail.respFlag)) {
                        if("1".equals(query.detail.mustPay)){
                            xmlTextWriter.writeElementString("unconditionalPayConsign","CC00");
                        }else{
                            throw new Exception("提示承兑同意签收，到期无条件支付委托只能传【CC00】");
                        }
                    }else{
                        xmlTextWriter.writeElementString("unconditionalPayConsign", "CC00");
                    }
                }else{
                    xmlTextWriter.writeElementString("unconditionalPayConsign", "CC00");
                }
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));
//                <signDate></signDate>
                xmlTextWriter.writeElementString("signDate",Format.Date8Format.format(new Date()));
//                <signResult></signResult>
                String signResult;
                if("1".equals(query.detail.respFlag)){
                    signResult = "SU00";
                }else {
                    signResult = "SU01";
                }
                xmlTextWriter.writeElementString("signResult",signResult);//应答结果

//                <signerType></signerType>
                String signerType = getBankConfig().getMapValueByKey("signerType",query.detail.actNum);//
                xmlTextWriter.writeElementString("signerType",signerType);//签收人类型(4)
//                <signerName></signerName>
                xmlTextWriter.writeElementString("signerName",String.format("%-62s",query.detail.respName));//签收人名称(62)
//                <acctNo></acctNo>
                xmlTextWriter.writeElementString("acctNo",String.format("%-32s",query.detail.actNum));//签收人开户账户(32)
                xmlTextWriter.writeElementString("signerLevel",query.detail.accpCredit );
                xmlTextWriter.writeElementString("signerRateOrg", query.detail.accpGrade);
                xmlTextWriter.writeElementString("signerRateDate", DateHelper.convertD10toD8(query.detail.accpGradeDue));
//                <signerAddress></signerAddress>
                xmlTextWriter.writeElementString("signerAddress", "");//签收人地址
//                <noPayReason></noPayReason>
                if("6".equals(query.detail.respType)&&"2".equals(query.detail.respFlag)) {
                    if(StringHelper.isNullOrEmpty(query.detail.unPayCode)){
                        throw new Exception("提示付款拒签时，拒付理由不能为空!");
                    }
                    if("99".equals(query.detail.unPayCode)){
                        xmlTextWriter.writeElementString("noPayReason", "10");
                        //                <noPayRemark></noPayRemark>
                        xmlTextWriter.writeElementString("noPayRemark", query.detail.unPayMemo);//拒付备注
                    }else{
                        xmlTextWriter.writeElementString("noPayReason", "0"+query.detail.unPayCode);
                        xmlTextWriter.writeElementString("noPayRemark", "");
                    }
                }else{
                    xmlTextWriter.writeElementString("noPayReason", "");
                    xmlTextWriter.writeElementString("noPayRemark","");
                }
                xmlTextWriter.writeElementString("remark",query.detail.memo);
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            retAts.writeDetail(detail);
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                        } else {
                            detail.respCode = "0";
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            retAts.writeDetail(detail);
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                        retAts.writeDetail(detail);
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                    retAts.writeDetail(detail);
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
                retAts.writeDetail(detail);
            }
        }
        try {
            conn.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }
    //出票申请
    @Override
    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception {
        RetAtsB101BillApplySubmit retAts = new RetAtsB101BillApplySubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB101BillApplySubmitDetail detail = new RetAtsB101BillApplySubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE02";
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                xmlTextWriter.writeStartElement("body");
//                transMasterID
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.drawAct));
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数,长度4
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt));//总金额，申请承兑金额
                String acceptanceType;
                if("1".equals(query.detail.accpSameBnk)){
                    acceptanceType ="00";//行内
                }else{
                    acceptanceType="01";//行外
                }
                xmlTextWriter.writeElementString("acceptanceType",acceptanceType);//行内行外标识
                String eBillType = query.detail.billType;
                String eDraweringTxType;
                if("01".equals(acceptanceType)){
                    if("1".equals(query.detail.autoPromptAccept)||"1".equals(query.detail.autoPromptReceipt)){
                        throw new Exception("承兑人不是浦发银行，不能自动提示承兑和提示收票");
                    }
                    eDraweringTxType = "01";
                    if("1".equals(eBillType)){
                        eBillType ="AC01";
                    }
                    else{
                        eBillType ="AC02";
                    }
                }else if("1".equals(eBillType)){
                    //银承
                    eBillType ="AC01";
                    if("1".equals(query.detail.autoPromptReceipt)){
                        eDraweringTxType = "03";//自动提示收票
                    }else if("1".equals(query.detail.autoPromptAccept))
                    {
                        eDraweringTxType = "02";//自动提示承兑
                    }else{
//                        throw new Exception("承兑人为同行的银承只能发起自动承兑和自动提示收票");
                        eDraweringTxType = "02";//自动提示承兑
                    }

                }else if("2".equals(eBillType)){
                    //商城
                    eBillType ="AC02";
                    if("1".equals(query.detail.autoPromptAccept)){
                        eDraweringTxType = "02";
                    }else if("1".equals(query.detail.autoPromptReceipt))
                    {
                        throw new Exception("承兑人为同行的商承不支持自动提示收票");
                    }else{
                        eDraweringTxType = "01";
                    }
                }else {
                    throw new Exception("票据类型异常："+eBillType);
                }
                xmlTextWriter.writeElementString("eDraweringTxType",eDraweringTxType);//交易类型
                xmlTextWriter.writeElementString("eBillType",eBillType);//票据类型
                xmlTextWriter.writeElementString("eDrawerType","RC01");//出票人类型(4)
                xmlTextWriter.writeElementString("acctNo",String.format("%-32s",query.detail.drawAct));//出票人账户(32)
//                xmlTextWriter.writeElementString("eDrawerBankNo",query.detail.drawBnkCode);
                if("AC01".equals(eBillType)){
                    String summaryEBillFlag  = "02";//是
                    xmlTextWriter.writeElementString("summaryEBillFlag",summaryEBillFlag);//是否按票据到期日汇总回单(2)
                    xmlTextWriter.writeElementString("discountingEBillFlag","");//是否申请保贴(2)

                }else{
                    String discountingEBillFlag  ="02";//否
                    xmlTextWriter.writeElementString("summaryEBillFlag","");//是否按票据到期日汇总回单(2)
                    xmlTextWriter.writeElementString("discountingEBillFlag",discountingEBillFlag);//是否申请保贴(2)
                }
                xmlTextWriter.writeElementString("bargainNo",String.format("%-30s",query.detail.contractNo));//合同编号(30)
                xmlTextWriter.writeElementString("invoiceNo",String.format("%-30s",query.detail.invoiceNo));//发票号码(30)
                xmlTextWriter.writeElementString("remark",query.detail.memo);//备注
                xmlTextWriter.writeStartElementByAttr("lists", "<lists name=\"edraftList\">");
                xmlTextWriter.writeStartElement("list");
//            <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号(4)
//            <billNo></billNo>
                xmlTextWriter.writeElementString("billNo","");//电子票号(30)n
//            <voteDate></voteDate>
                Date issDate = Format.DateTime21Format.parse(query.detail.issDate);
                if(-1==DateHelper.compareDay(issDate,new Date())){
                    throw new Exception("判断出票日期不得早于当日:" + query.detail.issDate);
                }
                xmlTextWriter.writeElementString("voteDate",Format.Date8Format.format(issDate));//出票日(8)
//            <expiryDate></expiryDate>
                Date expiryDate = Format.DateTime21Format.parse(query.detail.dueDate);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(issDate);
                calendar.add(Calendar.YEAR,1);
                if(-1==(DateHelper.compareDay(calendar.getTime(),expiryDate))){
                    throw new Exception("到期日与出票日的时间间隔不得超过一年");
                }
                xmlTextWriter.writeElementString("expiryDate",Format.Date8Format.format(expiryDate));//到期日(8)
                if("AC02".equals(eBillType)) {
//            <acceptorName></acceptorName>
                    xmlTextWriter.writeElementString("acceptorName", String.format("%-62s",query.detail.accpName)); //承兑人名称(62)
//            <acceptorAcctNo></acceptorAcctNo>
                    xmlTextWriter.writeElementString("acceptorAcctNo",String.format("%-32s",query.detail.accpAct));//承兑人账号(32)
//            <acceptorBankNo></acceptorBankNo>
                    xmlTextWriter.writeElementString("acceptorBankNo", String.format("%-12s",query.detail.accpBnkCode));//承兑人行号(12)
                }
//            <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//申请承兑金额
//            <canTransferFlag></canTransferFlag>
                if("1".equals(query.detail.transFlag)) {
                    xmlTextWriter.writeElementString("canTransferFlag","EM00");//转让
                }else {
                    xmlTextWriter.writeElementString("canTransferFlag","EM01");//
                }
//            <ePayeeAcctName></ePayeeAcctName>
                xmlTextWriter.writeElementString("ePayeeAcctName", String.format("%-62s",query.detail.payeeName));//收款人名称(62)
//            <ePayeeAcctNo></ePayeeAcctNo>
                xmlTextWriter.writeElementString("ePayeeAcctNo",String.format("%-32s",query.detail.payeeAct));//收款人开户账户(32)
//            <ePayeeBankNo></ePayeeBankNo>
                xmlTextWriter.writeElementString("ePayeeBankNo",String.format("%-12s",query.detail.payeeBnkCode) );//收款人开户行行号(12)
//            </list>
//            </lists>
//            </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //提示承兑
    @Override
    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception {
        RetAtsB102BillAccpSubmit retAts = new RetAtsB102BillAccpSubmit(query.reqHeader);
        retAts.writeBeforeDetail();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB102BillAccpSubmitDetail detail = new RetAtsB102BillAccpSubmitDetail();
        while (query.readRecord()) {
            Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE03";
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt));//总金额(13)
//                <eBillType></eBillType>
                String eBillType;
                if("1".equals(query.detail.billType)){
                    eBillType = "AC01";
                }else {
                    eBillType = "AC02";
                }
                xmlTextWriter.writeElementString("eBillType",eBillType);//票据类型(4)
//                <eDrawerType></eDrawerType>
                xmlTextWriter.writeElementString("eDrawerType","RC01");//出票人类型(4)
//                <acctNo></acctNo>
                xmlTextWriter.writeElementString("acctNo",String.format("%-32s",query.detail.actNum));//出票人开户账户(32)
//                <bargainNo></bargainNo>
                xmlTextWriter.writeElementString("bargainNo",String.format("%-30s",query.detail.contractNo));//合同编号(30)
//                <invoiceNo></invoiceNo>
                xmlTextWriter.writeElementString("invoiceNo",String.format("%-30s",query.detail.invoiceNo));//发票号码(30)
//                <remark></remark>
                xmlTextWriter.writeElementString("remark",query.detail.memo);//备注
//                <lists name="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists", "<lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");

//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号(4)
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票号(30)
//                <voteDate></voteDate>
                String voteDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.issDate));
                xmlTextWriter.writeElementString("voteDate",voteDate);//出票日(8)//
//                <expiryDate></expiryDate>
                String expiryDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.dueDate));
                xmlTextWriter.writeElementString("expiryDate",expiryDate);//到期日(8)
//                <applyAcceptanceAmount></applyAcceptanceAmount>
                xmlTextWriter.writeElementString("applyAcceptanceAmount",String.format("%13s",query.detail.billAmt));//申请承兑金额(13)
//                <canTransferFlag></canTransferFlag>
                if("1".equals(query.detail.transFlag)) {
                    xmlTextWriter.writeElementString("canTransferFlag","EM00");//转让
                }else {
                    xmlTextWriter.writeElementString("canTransferFlag","EM01");//
                }
//                <ePayeeAcctName></ePayeeAcctName>
                xmlTextWriter.writeElementString("ePayeeAcctName",String.format("%-62s",query.detail.payeeName) );//收款人名称(62)
//                <ePayeeAcctNo></ePayeeAcctNo>
                xmlTextWriter.writeElementString("ePayeeAcctNo",map.get("RECEIVERACTNO") );//收款人开户账户(32)
//                <ePayeeBankNo></ePayeeBankNo>
                xmlTextWriter.writeElementString("ePayeeBankNo", String.format("%-12s",query.detail.payeeBnkCode));//收款人开户行行号(12)
//                </list>
//                </lists>
//                </body>

                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
//                            URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //撤票
    @Override
    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception {
        RetAtsB103BillRetSubmit retAts = new RetAtsB103BillRetSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB103BillRetSubmitDetail detail = new RetAtsB103BillRetSubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode ="FE11";
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt) );//总金额(13)
//                <listsname="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists"," <lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");
//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");
//                <eDrawerNo></eDrawerNo>"
                xmlTextWriter.writeElementString("eDrawerNo",String.format("%20s",query.detail.billNo));
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));
//                </list>
//                </lists>
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //提示收票
    @Override
    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        RetAtsB104BillReceSubmit retAts = new RetAtsB104BillReceSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB104BillReceSubmitDetail detail = new RetAtsB104BillReceSubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE04";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt) );//总金额(13)
//                <eBillType></eBillType>
                String eBillType;
                if("1".equals(query.detail.billType)){
                    eBillType = "AC01";
                }else {
                    eBillType = "AC02";
                }
                xmlTextWriter.writeElementString("eBillType",eBillType);//票据类型
//                <eDrawerType></eDrawerType>
                xmlTextWriter.writeElementString("eDrawerType","RC01");//出票人类型(4) RC01 企业
//                <acctNo></acctNo>
                xmlTextWriter.writeElementString("acctNo",String.format("%-32s",query.detail.billOpenAcc));//出票人开户账户(32)
//                <remark></remark>
                xmlTextWriter.writeElementString("remark", query.detail.memo);//备注
//                <lists name="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists", "<lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");
//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号(4)
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo", String.format("%-30s",query.detail.billNo));//电子票号(30)
//                <voteDate></voteDate>
                String voteDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.issDate));
                xmlTextWriter.writeElementString("voteDate", voteDate);//出票日(8)
//                <expiryDate></expiryDate>
                String expiryDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.dueDate));
                xmlTextWriter.writeElementString("expiryDate",expiryDate);//到期日(8)
//                <applyAcceptanceAmount></applyAcceptanceAmount>
                xmlTextWriter.writeElementString("applyAcceptanceAmount", String.format("%13s",query.detail.billAmt));//申请承兑金额(13)
//                <canTransferFlag></canTransferFlag>
                if("1".equals(query.detail.transFlag)) {
                    xmlTextWriter.writeElementString("canTransferFlag","EM00");//转让
                }else {
                    xmlTextWriter.writeElementString("canTransferFlag","EM01");//
                }
//                <ePayeeAcctName></ePayeeAcctName>
                xmlTextWriter.writeElementString("ePayeeAcctName",String.format("%-62s",query.detail.payeeName) );//收款人名称(62)
//                <ePayeeAcctNo></ePayeeAcctNo>
                xmlTextWriter.writeElementString("ePayeeAcctNo",map.get("RECEIVERACTNO") );//收款人开户账户(32)
//                <ePayeeBankNo></ePayeeBankNo>
                xmlTextWriter.writeElementString("ePayeeBankNo",String.format("%-12s",query.detail.payeeBnkCode) );//收款人开户行行号(12)
//                </list>
//                </lists>
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //背书
    @Override
    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception {
        RetAtsB105BillEndoSubmit retAts = new RetAtsB105BillEndoSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB105BillEndoSubmitDetail detail = new RetAtsB105BillEndoSubmitDetail();
        while (query.readRecord()) {

            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE12";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt) );//总金额(13)
//                <remark></remark>
                xmlTextWriter.writeElementString("remark",query.detail.memo);//备注
//                <lists name="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists"," <lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");
//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//票面金额(13)
//                <endorsederName></endorsederName>
                xmlTextWriter.writeElementString("endorsederName",String.format("%-62s",query.detail.endoName));//背书人全称(62)
//                <endorsederType></endorsederType>
                xmlTextWriter.writeElementString("endorsederType","RC01");//背书人类型(4)
//                <endorsederAcctNo></endorsederAcctNo>
                xmlTextWriter.writeElementString("endorsederAcctNo",String.format("%-62s",query.detail.actNum));//背书人账号(32)
//                <endorsedApplyDate></endorsedApplyDate>
                xmlTextWriter.writeElementString("endorsedApplyDate",Format.Date8Format.format(new Date()));//背书申请日期(8)
//                <endorsedeeName></endorsedeeName>
                xmlTextWriter.writeElementString("endorsedeeName",String.format("%-62s",query.detail.receName));//被背书人名称(62)
//                <endorsedeeAcctNo></endorsedeeAcctNo>
                xmlTextWriter.writeElementString("endorsedeeAcctNo",String.format("%-32s",query.detail.receAct));//被背书人账号(32)
//                <endorsedeeBankNo></endorsedeeBankNo>
                xmlTextWriter.writeElementString("endorsedeeBankNo",String.format("%-12s",query.detail.receBnkCode));//被背书人开户行行号(12)
//                <canTransferFlag></canTransferFlag>
                String canTransferFlag;
                if("1".equals(query.detail.transFlag)) {
                    xmlTextWriter.writeElementString("canTransferFlag","EM00");//转让
                }else {
                    xmlTextWriter.writeElementString("canTransferFlag","EM01");//
                }
//                </list>
//                </lists>
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");

                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            //URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                            retAts.writeDetail(detail);
                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();

            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //贴现
    @Override
    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception {

        RetAtsB106BillDiscSubmit retAts = new RetAtsB106BillDiscSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB106BillDiscSubmitDetail detail = new RetAtsB106BillDiscSubmitDetail();
        while (query.readRecord()) {
            Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE07";
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",String.format("%13s",query.detail.billAmt) );//总金额(13)
//                <discountBankType></discountBankType>
                String discountBankType;
                if("1".equals(query.detail.receSameBnk)){
                    discountBankType = "00";
                }else {
                    discountBankType = "01";
                }
                xmlTextWriter.writeElementString("discountBankType",discountBankType);//行内行外标识(2)
//                <discountType></discountType>
                String discountType;
                if("1".equals(query.detail.discType)){
                    discountType="RM00";
                }else {
                    discountType="RM01";
                }
                xmlTextWriter.writeElementString("discountType",discountType);//贴现类型(4)RM00买断式   RM01回购式
//                <applyDiscountDate></applyDiscountDate>
                xmlTextWriter.writeElementString("applyDiscountDate",Format.Date8Format.format(new Date()));//申请贴现日期(8)
//                <discountTxType></discountTxType>
                xmlTextWriter.writeElementString("discountTxType","TT00");//交易类型(4)	TT00贴现 TT01转贴现―预留 TT02再贴现―预留
//                <discountRate></discountRate>
//                if("01".equals(discountBankType)) {
                BigDecimal discRate = new BigDecimal(query.detail.discRate);
                discRate = discRate.divide(new BigDecimal(100));
                xmlTextWriter.writeElementString("discountRate",discRate.toString());//贴现利率(9)
//                }
//                <interestType></interestType>00:卖方 01：买方 02：双方
                if("1".equals(query.detail.payInterestType)){
                    xmlTextWriter.writeElementString("interestType","00");//付息方式(2)
                }else if("2".equals(query.detail.payInterestType)){
                    xmlTextWriter.writeElementString("interestType","01");//付息方式(2)
                }else if("3".equals(query.detail.payInterestType)){
                    xmlTextWriter.writeElementString("interestType","02");//付息方式(2)
                }else{
                    xmlTextWriter.writeElementString("interestType","01");//付息方式(2)
                }
//                <recordedAcctNo></recordedAcctNo>
                xmlTextWriter.writeElementString("recordedAcctNo",String.format("%-32s",query.detail.actedAct) );//入账账号(32)
//                <recordedBankNo></recordedBankNo>
                if("01".equals(discountBankType)) {
                    xmlTextWriter.writeElementString("recordedBankNo",String.format("%-12s",query.detail.actedBnkCode) );//入账行号(12)
                }
//                <discounterType></discounterType>
                String discounterType = getBankConfig().getMapValueByKey("discounterType",query.detail.actNum);
                xmlTextWriter.writeElementString("discounterType",discounterType);//贴出人类型
//                <discounterName></discounterName>
                xmlTextWriter.writeElementString("discounterName",String.format("%-62s",query.detail.discName));//贴出人名称(62);
//                <acctNo></acctNo>
                xmlTextWriter.writeElementString("acctNo",String.format("%-32s",query.detail.actNum));//贴出人账户(32)
                if("01".equals(discountBankType)) {
//                <discounteeName></discounteeName>
                    xmlTextWriter.writeElementString("discounteeName",String.format("%-62s",query.detail.receName));//贴入人名称(62)
//                <discounteeAcctNo></discounteeAcctNo>
                    xmlTextWriter.writeElementString("discounteeAcctNo",String.format("%-32s",query.detail.receAct));//贴入人账户(32)
//                <discounteeBankNo></discounteeBankNo>
                    xmlTextWriter.writeElementString("discounteeBankNo", String.format("%-12s", query.detail.receBnkCode));//贴入人开户行行号(12)
                }else {
//                 <discounteeName></discounteeName>
                    xmlTextWriter.writeElementString("discounteeName",String.format("%-62s","0"));//贴入人名称(62)
//                <discounteeAcctNo></discounteeAcctNo>
                    xmlTextWriter.writeElementString("discounteeAcctNo",String.format("%-32s","0"));//贴入人账户(32)
//                <discounteeBankNo></discounteeBankNo>
                    xmlTextWriter.writeElementString("discounteeBankNo", String.format("%-12s","0"));//贴入人开户行行号(12)

                }
//                <liquidationType></liquidationType>
                String liquidationType ;
                if("1".equals(query.detail.payType)){
                    liquidationType  = "SM00";
                }else {
                    liquidationType = "SM01";
                }
                xmlTextWriter.writeElementString("liquidationType",liquidationType);//清算方式(4)
//                <remark></remark>
                xmlTextWriter.writeElementString("remark",query.detail.memo);//备注
//                <agentMark></agentMark>
                xmlTextWriter.writeElementString("agentMark","0");//代理标志(1)
//                <lists name="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists","<lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");
//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票据序列号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%20s",query.detail.billAmt));//票面金额(20)
                if("01".equals(discountBankType)) {
                    BigDecimal discAmt = getDiscAmt(query.detail);
                    xmlTextWriter.writeElementString("discountAmount",String.format("%13s", discAmt.setScale(2,BigDecimal.ROUND_HALF_UP)));//实付金额(13)
                }
//                <bargainNo></bargainNo>
                xmlTextWriter.writeElementString("bargainNo",String.format("%-30s",query.detail.contractNo));//交易合同编号(30)
//                <canTransferFlag></canTransferFlag>
                if("1".equals(query.detail.transFlag)) {
                    xmlTextWriter.writeElementString("canTransferFlag","EM00");//转让
                }else {
                    if("RM01".equals(discountType)){
                        throw  new Exception("回购式不得填不得转让");
                    }
                    xmlTextWriter.writeElementString("canTransferFlag","EM01");//
                }
                if("RM01".equals(discountType)) {
//                <redemptionOpenDate></redemptionOpenDate>
                    if(StringHelper.hasAnyChar(query.detail.repOpenDate)) {
//                                String redemptionOpenDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.repOpenDate));
                        String redemptionOpenDate = DateHelper.convertD10toD8(query.detail.repOpenDate);
                        xmlTextWriter.writeElementString("redemptionOpenDate",redemptionOpenDate);//贴现赎回开放日
                    }
//                <redemptionEndDate></redemptionEndDate>
                    if(StringHelper.hasAnyChar(query.detail.repDueDate)) {
//                                    String redemptionEndDate = Format.Date8Format.format(Format.DateTime21Format.parse(query.detail.repDueDate));
                        String redemptionEndDate = DateHelper.convertD10toD8(query.detail.repOpenDate);
                        xmlTextWriter.writeElementString("redemptionEndDate",redemptionEndDate);//贴现赎回截止日
                    }

                    if("01".equals(discountBankType)){
//                <redemptionRate></redemptionRate>
                        BigDecimal repRate = new BigDecimal(query.detail.repRate);
                        repRate = repRate.divide(new BigDecimal(100));
                        xmlTextWriter.writeElementString("redemptionRate", repRate.toString());//回购利率(9)
//                <redemptionAmount></redemptionAmount>
                        xmlTextWriter.writeElementString("redemptionAmount",String.format("%13s",query.detail.repAmt));//回购实付金额(13)
                    }
                }
//                </list>
//                </lists>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");

                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            //URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");

                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //质押
    @Override
    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception {
        RetAtsB107BillPledSubmit retAts = new RetAtsB107BillPledSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB107BillPledSubmitDetail detail = new RetAtsB107BillPledSubmitDetail();
        while (query.readRecord()) {

            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE09";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票据序列号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//票面金额(13)
//                <pledgerName></pledgerName>
                xmlTextWriter.writeElementString("pledgerName",String.format("%-62s",query.detail.pledName));//出质人全称(62)
//                <pledgerType></pledgerType>
                String pledgerType = getBankConfig().getMapValueByKey("pledgerType",query.detail.actNum);
                xmlTextWriter.writeElementString("pledgerType",pledgerType);//出质人类型(4)
//                <pledgeeName></pledgeeName>
                xmlTextWriter.writeElementString("pledgeeName",String.format("%-62s",query.detail.receName));//质权人全称
//                pledgeeAcctNo	质权人账号	FixString(32）
                xmlTextWriter.writeElementString("pledgeeAcctNo",String.format("%-32s",query.detail.receAct));//质权人账号
//                <pledgeeBankNo></pledgeeBankNo>
                xmlTextWriter.writeElementString("pledgeeBankNo",String.format("%-62s",query.detail.receBnkCode));//质权人开户行行号
//                <pledgeApplyDate></pledgeApplyDate>
                xmlTextWriter.writeElementString("pledgeApplyDate",Format.Date8Format.format(new Date()));//质押申请日期(8)
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");

                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            //URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");

                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();

            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;

    }
    //提示付款
    @Override
    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception {
        RetAtsB108BillPaySubmit retAts = new RetAtsB108BillPaySubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB108BillPaySubmitDetail detail = new RetAtsB108BillPaySubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE14";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <totalNumber></totalNumber>
                xmlTextWriter.writeElementString("totalNumber",String.format("%4s","1"));//总笔数(4)
//                <totalAmount></totalAmount>
                xmlTextWriter.writeElementString("totalAmount",query.detail.billAmt);//总金额(13)
//                <remark></remark>
                xmlTextWriter.writeElementString("remark",query.detail.memo);
//                <lists name="edraftList">
                xmlTextWriter.writeStartElementByAttr("lists","<lists name=\"edraftList\">");
//                <list>
                xmlTextWriter.writeStartElement("list");
//                <sequenceNo></sequenceNo>
                xmlTextWriter.writeElementString("sequenceNo","0001");//序号(4)
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",query.detail.billNo);//电子票号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",query.detail.billAmt);//票面金额(13)
//                <cuePayType></cuePayType>
                String cuePayType;
                if("1".equals(query.detail.proPayType)){
                    cuePayType = "01";
                }else {
                    cuePayType = "02";
                }
                xmlTextWriter.writeElementString("cuePayType",cuePayType);//提示付款类型(2)
//                cuePayerAcctNo	提示付款人账号	FixString(32)
                xmlTextWriter.writeElementString("cuePayerAcctNo",query.detail.actNum);
//                bondeeBankNo	提示付款人开户行行号	FixString(12)
                xmlTextWriter.writeElementString("bondeeBankNo",query.detail.actBnkCode);
//                <cuePayerName></cuePayerName>
                // 提示付款人名称需要在配置文件里面配置
                xmlTextWriter.writeElementString("cuePayerName",query.detail.actName);
//                <cuePayerType></cuePayerType>
                String cuePayerType = getBankConfig().getMapValueByKey("cuePayerType",query.detail.actNum);
                xmlTextWriter.writeElementString("cuePayerType",cuePayerType);//提示付款人类型(4)
//                <cuePayApplyDate></cuePayApplyDate>
                xmlTextWriter.writeElementString("cuePayApplyDate",Format.Date8Format.format(new Date()));//提示付款申请日期(8)
//                <cuePayAmount></cuePayAmount>
                xmlTextWriter.writeElementString("cuePayAmount",query.detail.billAmt);//提示付款金额（13）
//                <lineLiquidationFlag></lineLiquidationFlag>
//                String lineLiquidationFlag;
//                String flag = getBankConfig().getMapValueByKey("lineLiquidationFlag",query.detail.billNo);
//                if("0".equals(flag)&&"1".equals(query.detail.payType)){
//                    lineLiquidationFlag = "SM00";
//                }else {
//                    lineLiquidationFlag = "SM01";
//                }
                xmlTextWriter.writeElementString("lineLiquidationFlag","SM01");//线上清算标志(4)
//                <overdueRemark></overdueRemark>
                xmlTextWriter.writeElementString("overdueRemark", query.detail.overDueRea);//逾期说明
//                </list>
//                </lists>
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
//                            URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //提示保证
    @Override
    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception {
        RetAtsB109BillGuarSubmit retAts = new RetAtsB109BillGuarSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB109BillGuarSubmitDetail detail = new RetAtsB109BillGuarSubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode="EE13";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票据序列号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//票面金额
//                <bondType></bondType>
                String bondType;
                String flag = getBankConfig().getMapValueByKey("lineLiquidationFlag",query.detail.billNo);
                if("1".equals(flag)){
                    bondType = "02";
                }else {
                    if ("1".equals(query.detail.guarType)) {
                        bondType = "01";
                    } else if ("2".equals(query.detail.guarType)) {
                        bondType = "02";
                    } else {
                        bondType = "03";
                    }
                }
                xmlTextWriter.writeElementString("bondType",bondType);//保证类型(2)
//                <bondeeName></bondeeName>
                xmlTextWriter.writeElementString("bondeeName",String.format("%-62s",query.detail.guarName));//被保证人全称(62)
                String bondeeType;
                bondeeType = getBankConfig().getMapKeyByValue("bondeeType",query.detail.actNum);
//                <bondeeType></bondeeType>
                xmlTextWriter.writeElementString("bondeeType",String.format("%-30s",bondeeType));//被保证人类型(4)
//                <bondApplyDate></bondApplyDate>
                xmlTextWriter.writeElementString("bondApplyDate",Format.Date8Format.format(new Date()));//保证申请日期(8)
//                <bonderName></bonderName>
                xmlTextWriter.writeElementString("bonderName",String.format("%-62s",query.detail.receName));//保证人名称(62)
//                <bonderAcctNo></bonderAcctNo>
                xmlTextWriter.writeElementString("bonderAcctNo",String.format("%-32s",query.detail.receAct));//保证人账号(32)
//                <bonderBankNo></bonderBankNo>
                xmlTextWriter.writeElementString("bonderBankNo",String.format("%-12s",query.detail.receBnkCode));//保证人开户行行号(12)
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //追索通知
    @Override
    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception {
        RetAtsB110BillRecoSubmit retAts = new RetAtsB110BillRecoSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB110BillRecoSubmitDetail detail = new RetAtsB110BillRecoSubmitDetail();
        while (query.readRecord()) {
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE15";
            try {
                Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//票面金额(13)
//                <recourseType></recourseType>
                String recourseType;
                if("1".equals(query.detail.recourseType)){
                    recourseType ="RT00";
                }else {
                    recourseType ="RT01";
                }
                xmlTextWriter.writeElementString("recourseType",recourseType);
//                <recourseApplyDate></recourseApplyDate>
                xmlTextWriter.writeElementString("recourseApplyDate",Format.Date8Format.format(new Date()));//追索申请日期
//                <recourseAmount></recourseAmount>
                xmlTextWriter.writeElementString("recourseAmount",String.format("%13s",query.detail.recourseAmt));//追索金额(13)
//                <recourserName></recourserName>
                xmlTextWriter.writeElementString("recourserName",String.format("%-60s",query.detail.recoName));//追索人全称(62)
//                <recourserType></recourserType>
                String recourserType = getBankConfig().getMapValueByKey("recourserType",query.detail.actNum);
                xmlTextWriter.writeElementString("recourserType",recourserType);
//                <organizeCode></organizeCode>
                xmlTextWriter.writeElementString("organizeCode",String.format("%-20s",query.detail.receCode ));//被追索人组织机构代码(20)
//                <recourseeName></recourseeName>
                xmlTextWriter.writeElementString("recourseeName",String.format("%-62s",query.detail.receName ));//被追索人名称(62)
//                <recourseeAcctNo></recourseeAcctNo>
                xmlTextWriter.writeElementString("recourseeAcctNo",String.format("%-32s",query.detail.receAct ));//被追索人账号(32)
//                <recourseeBankNo></recourseeBankNo>
                xmlTextWriter.writeElementString("recourseeBankNo",String.format("%-12s",query.detail.receBnkCode ));//被追索人开户行行号(12)
//                <recourseReason></recourseReason>
                if("RT01".equals(recourseType)) {
                    if ("1".equals(query.detail.recourseCode)) {
                        xmlTextWriter.writeElementString("recourseReason", "RC00");//追索理由
                    } else {
                        xmlTextWriter.writeElementString("recourseReason", "RC01");//追索理由

                    }
                }
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            //URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                    map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                    map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                    map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();

            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //同意清偿
    @Override
    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception {
        RetAtsB111BillAgreeSubmit retAts = new RetAtsB111BillAgreeSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB111BillAgreeSubmitDetail detail = new RetAtsB111BillAgreeSubmitDetail();
        while (query.readRecord()) {
            try {
                Map<String,String> map = queryBillByEE25(query);
                Map<String,String> map1 = getBillInfo(query.detail.billNo,query.detail.actNum);
                if(map==null){
                    throw new Exception("获取同意清偿人信息失败！");
                }
                SPDB01Header header = new SPDB01Header();
                header.transCode = "EE16";
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt));//票面金额（13）
//                <eBillBusinessId></eBillBusinessId>
                xmlTextWriter.writeElementString("eBillBusinessId",String.format("%-20s",query.detail.busiNo));//业务ID(20)
//                liquidityerAcctNo	同意清偿人账号	FixString(32)	N	无需填写，系统自动读取票据信息
                xmlTextWriter.writeElementString("liquidityerAcctNo",String.format("%-32s",map.get("payeeAcctNo")));//同意清偿人账号(62)
//                <liquidityerName></liquidityerName>
                xmlTextWriter.writeElementString("liquidityerName",String.format("%-62s",map.get("payeeAcctName")));//同意清偿人全称(62)
//                <liquidityerType></liquidityerType>
                xmlTextWriter.writeElementString("liquidityerType",map.get("payeeType"));//同意清偿人类型
//                <liquidityerOrgId></liquidityerOrgId>
                xmlTextWriter.writeElementString("liquidityerOrgId",String.format("%-20s",map.get("payeeOrgId")));//同意清偿人组织机构代码证(20)
//                <liquidityerBankNo></liquidityerBankNo>
                xmlTextWriter.writeElementString("liquidityerBankNo",String.format("%-12s",map.get("payeeBankNo")));//同意清偿人开户行行号(12)
//                <liquidityDate></liquidityDate>
                xmlTextWriter.writeElementString("liquidityDate",Format.Date8Format.format(new Date()));//同意清偿日期
//                <liquidityAmount></liquidityAmount>
                xmlTextWriter.writeElementString("liquidityAmount",String.format("%13s",query.detail.agreeAmt));//同意清偿金额(13)
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");

                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                            //URID,BANKCODE,BILLNO,BILLAMOUNT,BUSITYPE,OUTREQSEQID,TRANSDATE,APPLYNAME,APPLYACTNO,APPLYBANKCODE,APPLYBANKNAME,RECNAME,RECACTNO,RECBANKCODE,RECBANKNAME,ISFINISHED,ISCANCEL
                            JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                    header.transCode,businessId,transDate,
                                    map1.get("BILLNO"), map1.get("BILLAMOUNT"), map1.get("BILLTYPE"), map1.get("ISSDATE"), map1.get("DUEDATE"), map1.get("TRANSFLAG"),
                                    map1.get("DRAWERNAME"), map1.get("DRAWERACTNO"), map1.get("DRAWERBANKCODE"), map1.get("DRAWERBANKNAME"),
                                    map1.get("ACCEPTORNAME"), map1.get("ACCEPTORACTNO"), map1.get("ACCEPTORBANKCODE"), map1.get("ACCEPTORBANKNAME"),
                                    map1.get("RECEIVERNAME"), map1.get("RECEIVERACTNO"), map1.get("RECEIVERBANKCODE"), map1.get("RECEIVERBANKNAME")});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");

                        }

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];

                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();

            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }
    //通用撤销
    @Override
    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception {
        RetAtsB112BillCancSubmit retAts = new RetAtsB112BillCancSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn =FGBiz.getLocalDbConn();
        RetAtsB112BillCancSubmitDetail detail = new RetAtsB112BillCancSubmitDetail();
        while (query.readRecord()) {

            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE05";
            Map<String,String> map = queryTransJnlNo(query.detail.busiNo,query.detail.actNum);
            if("false".equals(map.get("isCancle"))){
                detail.respCode = "0";
                detail.transState ="2" ;
                detail.payInfoCode = "2";
                detail.reqSeqID = query.detail.reqSeqID;
                retAts.writeDetail(detail);
                JDBCHelper.update(conn,UPDATECANCEL,new Object[]{"3",query.detail.busiNo,query.detail.billNo});
            }
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
//                <body>.
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <eBillBusinessId></eBillBusinessId>
                xmlTextWriter.writeElementString("eBillBusinessId", String.format("%-10s",map.get("transJnlNo")));//流水表ID(10)
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",String.format("%-30s",query.detail.billNo));//电子票据序列号(30)
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount",String.format("%13s",query.detail.billAmt) );//票面金额(13)
//                <oldTransDate></oldTransDate>
                xmlTextWriter.writeElementString("oldTransDate",map.get("transDate") );//原交易日期
//                <oldTransJnlNo></oldTransJnlNo>
                xmlTextWriter.writeElementString("oldTransJnlNo", String.format("%-10s",map.get("businessId")));//原交易流水号(10)
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpbkMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                            detail.reqSeqID = query.detail.reqSeqID;
                            String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                            String uuid =UUID.randomUUID().toString().replaceAll("-","");
                            //用于在撤销状态查询之后定位相应的撤销记录
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId+"_"+query.detail.busiNo});
                            JDBCHelper.update(conn,UPDATECANCEL,new Object[]{"2",query.detail.busiNo,query.detail.billNo});
                        } else {
                            detail.respCode = "0";
                            detail.transState = returnCode;
                            detail.payInfoCode = returnCode;
                            detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");

                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpbkMsg.toString();

                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            } catch (Exception e) {
                detail.respCode = "-1";
                detail.respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        try {
            conn.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        RetAtsB119BillRelePledSubmit retAts = new RetAtsB119BillRelePledSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        RetAtsB119BillRelePledSubmitDetail detail = new RetAtsB119BillRelePledSubmitDetail();
        query.readRecord();
        SPDB01Header header = new SPDB01Header();
        header.transCode ="EE10";
        try {
            Map<String,String> map = getBillInfo(query.detail.billNo,query.detail.actNum);
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            xmlTextWriter.writeStartElement("body");
            xmlTextWriter.writeElementString("transMasterID", getTransMasterID(query.detail.actNum));
            xmlTextWriter.writeElementString("billNo", query.detail.billNo);
            xmlTextWriter.writeElementString("amount", query.detail.billAmt);
            xmlTextWriter.writeElementString("pledgeLiftApplyDate", Format.Date8Format.format(new Date()));
            xmlTextWriter.writeElementString("pledgeeName", query.detail.pledgeeName);
            xmlTextWriter.writeElementString("pledgeeSignature", query.detail.pledgeeName);
            xmlTextWriter.writeElementString("acctNo",query.detail.actNum );
            xmlTextWriter.writeElementString("pledgeeBankNo", query.detail.pledgeeBnkCode);
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
            if (result[0].length() == 0) {
                StringBuilder tmpbkMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpbkMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                    if (returnCode != null && "AAAAAAA".equals(returnCode)) {
                        detail.respCode = "0";
                        detail.transState = returnCode;
                        detail.payInfoCode = returnCode;
                        detail.reqSeqID = query.detail.reqSeqID;
                        String businessId = tmpbkReader.getFirstText("/packet/body/businessId");
                        String transDate = tmpbkReader.getFirstText("/packet/body/transDate");
                        String uuid =UUID.randomUUID().toString().replaceAll("-","");
                        JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,header.transCode,transDate,detail.reqSeqID,businessId});
                        JDBCHelper.update(conn,INSERTCANCEL,new Object[]{uuid,query.reqHeader.bankCode,
                                header.transCode,businessId,transDate,
                                map.get("BILLNO"), map.get("BILLAMOUNT"), map.get("BILLTYPE"), map.get("ISSDATE"), map.get("DUEDATE"), map.get("TRANSFLAG"),
                                map.get("DRAWERNAME"), map.get("DRAWERACTNO"), map.get("DRAWERBANKCODE"), map.get("DRAWERBANKNAME"),
                                map.get("ACCEPTORNAME"), map.get("ACCEPTORACTNO"), map.get("ACCEPTORBANKCODE"), map.get("ACCEPTORBANKNAME"),
                                map.get("RECEIVERNAME"), map.get("RECEIVERACTNO"), map.get("RECEIVERBANKCODE"), map.get("RECEIVERBANKNAME")});
                    } else {
                        detail.respCode = "0";
                        detail.transState = returnCode;
                        detail.payInfoCode = returnCode;
                        detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpbkMsg.toString();
                }
            } else {
                detail.respCode = "-1";
                detail.respInfo = result[1];
            }
        } catch (Exception e) {
            detail.respCode = "-1";
            detail.respInfo = e.getMessage();
            e.printStackTrace();
        }finally {
            try {
                conn.close();
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }

    private Map<String,String> queryTransJnlNo(String reqseqId,String actNum) throws Exception{
        Connection conn = FGBiz.getLocalDbConn();
        Map<String,String> respMap = new HashMap<String, String>();
        try{
            Map<String,Object> map = JDBCHelper.execQuerySingle(conn,SELECTRECEIPT,new Object[]{reqseqId});

            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            String transCode = map.get("BUSITYPE").toString();
            String businessId = map.get("BANKREQSEQID").toString();
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE26";
            xmlTextWriter.writeStartElement("body");
            xmlTextWriter.writeElementString("transMasterID",getTransMasterID(actNum));
//        hostTxnCode	查询交易代码	FixString(4)	Y	交易代码
            xmlTextWriter.writeElementString("hostTxnCode",transCode);//查询交易代码(4)
            xmlTextWriter.writeElementString("businessId",businessId);//交易流水号(10)
//        beginNumber	起始记录数	FixNumber(4)	Y	最小1
            xmlTextWriter.writeElementString("beginNumber",String.format("%4s","1"));//起始记录数(4)
//        queryNumber	查询记录数	FixNumber(4)	Y	最大20笔
            xmlTextWriter.writeElementString("queryNumber",String.format("%4s","2"));//查询记录数(4)
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString(),header);
            if(result[0].length() ==0){
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                if(tmpbkReader!=null){
//                totalNumber	总记录数	FixNumber(4)
//                循环
//                hostTxnCode	交易代码	FixString(4)
//                transDate	交易日期	FixString(8)
//                transJnlNo	业务流水号	FixString(20)
//                eBillBatchNo	网银批次号	FixString(18)		批量文件方式的业务可提供交易批次号，用于EE28查询
//                businessId	网银流水号	FixString(10)
//                eCDSFlag	ECDS报文标识号	FixString(35)
//                eCDSDate	ECDS报文日期时间	FixString(14)
//                billNo	电子票据序列号	 FixString(30)
//                eBillAmount	票面金额	FixString(13,2)
                    String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                    if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                        String totalNumber = tmpbkReader.getFirstText("/packet/body/totalNumber").trim();
                        if(!"1".equals(totalNumber)){
                            throw new Exception("明细记录获取失败,请稍后再查："+totalNumber);
                        }
                        if(tmpbkReader.read("/packet/body/lists/list")){
                            String state = tmpbkReader.readedXElement.getSingleText("eBillJnlStatus");
                            if("1".equals(state)||"4".equals(state)){
                                respMap.put("isCancle","true");
                                respMap.put("transJnlNo",tmpbkReader.readedXElement.getSingleText("transJnlNo"));
                                respMap.put("eBillBatchNo",tmpbkReader.readedXElement.getSingleText("eBillBatchNo"));
                                respMap.put("businessId",tmpbkReader.readedXElement.getSingleText("businessId"));
                                respMap.put("transDate",tmpbkReader.readedXElement.getSingleText("transDate"));
                            }else if("2".equals(state)||"3".equals(state)||"5".equals(state)||"6".equals(state)){
                                respMap.put("isCancle","false");
                            }else{
                                throw new Exception("银行对原交易的处理状态异常，请核查："+state);
                            }
                        }
                    }else{
                        throw new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg").trim());
                    }
                }else{
                    throw new Exception(tmpsbMsg.toString());
                }
            }else
            {
                throw new Exception(result[1]);
            }
        }catch (Exception ex){
            throw  ex;
        }finally {
            conn.close();
        }
        return respMap;
    }

    private Map<String,String> queryBillByEE25(ReqB111BillAgreeSubmit query)throws Exception{
        int numStart = 1;
        int totalNum = 0;
        do {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE25";
//                <body>
            xmlTextWriter.writeStartElement("body");
//                    transMasterID	交易客户号	FixNumber(10)		备用字段
            xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                    eBillBusessType	查询类别	FixString(2)	Y
            xmlTextWriter.writeElementString("eBillBusessType","19" );
//                    eBillType	票据种类	FixString(4)	N	AC01银承 AC02商承
            xmlTextWriter.writeElementString("eBillType","" );
//                    beginDate	对方行业务申请开始日期	FixString(8)	Y
            xmlTextWriter.writeElementString("beginDate","" );//票据到期日开始日期
//                    endDate	对方行业务申请结束日期	FixString(8)	Y
            xmlTextWriter.writeElementString("endDate","" );//票据到期日结束日期
//                    beginNumber	起始记录数	FixNumber(4)	Y	最小为1
            xmlTextWriter.writeElementString("beginNumber", String.format("%4s",numStart));//起始记录数(4)
//                <queryNumber></queryNumber>
            xmlTextWriter.writeElementString("queryNumber", String.format("%4s",10));//查询记录数(4)
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                    if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                        if(totalNum==0){
                            totalNum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                        }
                        while (tmpbkReader.read("/packet/body/lists/list")) {
                            numStart++;
//                                    billNo	电子票据序列号	FixString(30)
                            String billNo =tmpbkReader.readedXElement.getSingleText("billNo").trim();
                            if(query.detail.billNo.equals(billNo)) {
                                Map<String,String> payInfo = new HashMap<String,String>();
//                                    ePayeeAcctName	接收人名称	FixString(62)
                                payInfo.put("payeeAcctName",tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim());
//                                ePayeeType	接收人类型	FixString(4)
                                payInfo.put("payeeType",tmpbkReader.readedXElement.getSingleText("ePayeeType").trim());
//                                    ePayeeAcctNo	接收人账号	FixString(20)
                                payInfo.put("payeeAcctNo",tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim());
//                                    ePayeeOrgId	接收人组织机构代码	FixString(32)
                                payInfo.put("payeeOrgId",tmpbkReader.readedXElement.getSingleText("ePayeeOrgId").trim());
//                                    ePayeeBankNo	接收人行号	FixString(12)
                                payInfo.put("payeeBankNo",tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim());
                                return payInfo;

                            }
                        }
                    }else {
                        throw  new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg"));
                    }
                } else {
                    throw  new Exception(tmpsbMsg.toString());
                }

            } else {
                throw new Exception(result[1]);
            }
        }while (numStart<=totalNum);
        return null;
    }


    public Map<String,String> getBillInfo(String billNo,String actnum)throws Exception{
        Map<String,String>  map = null;
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        SPDB01Header header = new SPDB01Header();
        header.transCode ="EE22";
//                <body>
        xmlTextWriter.writeStartElement("body");
        xmlTextWriter.writeElementString("transMasterID",getTransMasterID(actnum));
//                <billNo></billNo>
        xmlTextWriter.writeElementString("billNo",billNo);//票据号码
//                </body>
        xmlTextWriter.writeEndDocument();
        String[] result = sendToBank(xmlTextWriter.toXmlString(),header);
        if(result[0].length()==0){
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
            if(tmpbkReader!=null){
                String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                    if (tmpbkReader.read("/packet/body")){
                        map = new HashMap<String, String>();
                        map.put("BILLNO",tmpbkReader.readedXElement.getSingleText("billNo").trim());//票据号
                        String eBillType = tmpbkReader.readedXElement.getSingleText("eBillType").trim();//票据类型
                        if("AC01".equals(eBillType)){
                            eBillType = "1";
                        }else if("AC02".equals(eBillType)){
                            eBillType= "2";
                        }
                        map.put("BILLTYPE",eBillType);
                        map.put("BILLAMOUNT",tmpbkReader.readedXElement.getSingleText("eBillAmount").trim());//票据金额
                        map.put("ISSDATE",DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("voteDate").trim()));//出票日期
                        map.put("DUEDATE",DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("expiryDate").trim()));//到期日
                        String canTransferFlag =tmpbkReader.readedXElement.getSingleText("canTransferFlag").trim();//转让标记
                        if("EM00".equals(canTransferFlag)){
                            canTransferFlag = "1";
                        }else if("EM01".equals(canTransferFlag)){
                            canTransferFlag = "2";
                        }
                        map.put("TRANSFLAG",canTransferFlag);
                        map.put("DRAWERNAME",tmpbkReader.readedXElement.getSingleText("eDrawerName").trim());//出票人名称
                        map.put("DRAWERACTNO",tmpbkReader.readedXElement.getSingleText("eDrawerAcctNo").trim());//出票人账号
                        map.put("DRAWERBANKCODE",tmpbkReader.readedXElement.getSingleText("eDrawerBankNo").trim());//出票人开户行行号
                        map.put("DRAWERBANKNAME",tmpbkReader.readedXElement.getSingleText("drawerBankName").trim());//出票人开户行名称
                        map.put("RECEIVERNAME",tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim());//收款人名称
                        map.put("RECEIVERACTNO",tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim());//收款人账号
                        map.put("RECEIVERBANKCODE",tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim());//收款人开户行行号
                        map.put("RECEIVERBANKNAME",tmpbkReader.readedXElement.getSingleText("payeeHostBankName").trim());//收票人开户行名称
                        map.put("ACCEPTORNAME",tmpbkReader.readedXElement.getSingleText("acceptorName").trim());//承兑人名称
                        map.put("ACCEPTORACTNO",tmpbkReader.readedXElement.getSingleText("acceptorAcctNo").trim());//承兑人账号
                        map.put("ACCEPTORBANKCODE",tmpbkReader.readedXElement.getSingleText("acceptorBankNo").trim());//承兑人开户行行号
                        map.put("ACCEPTORBANKNAME",tmpbkReader.readedXElement.getSingleText("acceptBankName").trim());//承兑行名称
                        return map;
                    }
                }else {
                    throw new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg"));
                }
            }else {
                throw new Exception(tmpsbMsg.toString());
            }
        }else {
            throw new Exception(result[1]);
        }
        if (map==null){
            throw new Exception("获取票据信息失败");
        }else{
            return map;
        }
    }
}
